package io.terminus.spzx.manager.controller;

import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.terminus.spzx.manager.service.CategoryBrandService;
import io.terminus.spzx.model.dto.product.CategoryBrandDto;
import io.terminus.spzx.model.entity.product.Brand;
import io.terminus.spzx.model.entity.product.CategoryBrand;
import io.terminus.spzx.model.vo.common.Result;
import io.terminus.spzx.model.vo.common.ResultCodeEnum;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author lichunlong lcl253137@alibaba-inc.com
 * @Desc 分类品牌管理Controller
 * @Date 2024-10-08
 */
@RestController
@RequiredArgsConstructor
@Tag(name = "分类品牌管理接口")
@RequestMapping(value = "/admin/product/categoryBrand")
public class CategoryBrandController {

    private final CategoryBrandService categoryBrandService;

    /**
     * 分页查询分类品牌
     *
     * @param page             当前页
     * @param limit            每页记录数
     * @param CategoryBrandDto 查询条件
     * @return 分类品牌分页列表
     */
    @GetMapping("/{page}/{limit}")
    public Result<PageInfo<CategoryBrand>> findByPage(@PathVariable Integer page, @PathVariable Integer limit, CategoryBrandDto CategoryBrandDto) {
        PageInfo<CategoryBrand> pageInfo = categoryBrandService.findByPage(page, limit, CategoryBrandDto);

        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }

    /**
     * 根据分类ID查询品牌
     *
     * @param categoryId 分类ID
     * @return 品牌列表
     */
    @GetMapping("/findBrandByCategoryId/{categoryId}")
    public Result<List<Brand>> findBrandByCategoryId(@PathVariable Long categoryId) {
        List<Brand> brandList = categoryBrandService.findBrandByCategoryId(categoryId);

        return Result.build(brandList, ResultCodeEnum.SUCCESS);
    }

    /**
     * 添加分类品牌
     *
     * @param categoryBrand 分类品牌
     * @return 添加结果
     */
    @PostMapping("/save")
    public Result<Void> save(@RequestBody CategoryBrand categoryBrand) {
        categoryBrandService.save(categoryBrand);

        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    /**
     * 修改分类品牌
     *
     * @param categoryBrand 分类品牌
     * @return 修改结果
     */
    @PutMapping("updateById")
    public Result<Void> updateById(@RequestBody CategoryBrand categoryBrand) {
        categoryBrandService.updateById(categoryBrand);

        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    /**
     * 删除品牌
     *
     * @param id 品牌ID
     * @return 删除结果
     */
    @DeleteMapping("/deleteById/{id}")
    public Result<Void> deleteById(@PathVariable Long id) {
        categoryBrandService.deleteById(id);

        return Result.build(null, ResultCodeEnum.SUCCESS);
    }
}
